package com.small.nacos.config.server.service.datasource;

import com.small.nacos.core.datasource.DataSourceService;
import com.small.nacos.core.datasource.ExternalDataSourceServiceImpl;
import com.small.nacos.sys.utils.PropertyUtil;

public class DynamicDataSource {

    private static final DynamicDataSource dynamicDataSource = new DynamicDataSource();

    private DataSourceService basicDataSourceService = null;


    public static DynamicDataSource getInstance(){
        return dynamicDataSource;
    }

    public synchronized DataSourceService getDataSource(){
        try {
            if (!PropertyUtil.isEmbeddedStorage()) {
                if (basicDataSourceService == null) {
                    basicDataSourceService = new ExternalDataSourceServiceImpl();
                    basicDataSourceService.init();
                }
                return basicDataSourceService;
            }
            throw new RuntimeException("no DataSourceService");
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
